//
//  AppDelegate+JSPatch.m
//  kdxf_test
//
//  Created by iOS-01 on 16/11/2.
//  Copyright © 2016年 iOS-01. All rights reserved.
//

#import "AppDelegate+JSPatch.h"
#import <JSPatch/JPEngine.h>

@implementation AppDelegate (JSPatch)

- (void)jsPatchInit {
    //    [self loadJSPatchFromServer];
    [self loadJSPatchFromLocal];
}

- (void)loadJSPatchFromLocal {
    [JPEngine startEngine];
    NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"js"];
    NSString *script = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:nil];
    [JPEngine evaluateScript:script];
}

//- (void)loadJSPatchFromServer{
//    NSString *build = [BLSystemUtils applicationBuild];
//    
//    [BLNetRequest NetRequestPOSTWithRequestURL:@"/login/iosversion" WithParameter:@{@"build":build} WithReturnValeuBlock:^(id returnValue) {
//        NSDictionary *returnDic = returnValue[DATA];
//        NSString *newScript;
//        if ([returnDic isKindOfClass:[NSDictionary class]]) {
//            newScript = returnDic[@"script"];
//        } else {
//            newScript = @"";
//        }
//        setUD_(@"JSPatch_script", newScript);
//        setUD_(@"JSPatch_Build", build);
//        [JPEngine startEngine];
//        [JPEngine evaluateScript:newScript];
//        
//    } WithErrorCodeBlock:^(id errorCode) {
//        
//    } WithFailureBlock:^{
//        
//        NSString *localPS = UD_(@"JSPatch_script");
//        if (!localPS.length) {
//            return;
//        }
//        if ([build isEqualToString:UD_(@"JSPatch_Build")] && localPS.length) {
//            [JPEngine startEngine];
//            [JPEngine evaluateScript:UD_(@"JSPatch_script")];
//        }
//        
//    } encryptType:EncryptAES128 decryptType:EncryptAES128];
//    
//}


@end
